#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time    : 2021/7/4 18:08
# @Author  : Aaron
# @File    : main_page
# @Software: PyCharm


from calculator_pytest.po.base_page import BasePage
from calculator_pytest.po.contact_page import ContactPage
from calculator_pytest.tools import get_datas
from calculator_pytest.tools import generate_yml

class MainPage(BasePage):

    def go_contact(self) -> ContactPage:
        """
        获取url
        导入cookie
        点击通讯录
        :return:
        """
        driver = self.driver
        url = get_datas.get_selenium_data(
            "selenium.yml").get('enterprise_wechat_url')[0]
        driver.get(url)

        try:
            generate_yml.generate_cookie_yml()
        except Exception as e:
            print(e)

        cookies = get_datas.get_selenium_data(
            "enterprise_wechat_cookie.yml")

        for cookie in cookies:
            driver.add_cookie(cookie)

        driver.refresh()
        driver.find_element_by_id("menu_contacts").click()

        return ContactPage(self.driver)
